<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>菜单列表</title>
  <link rel="stylesheet" href="./css/style.css" />
</head>
<style>
  .list-box {
    text-align: center;
    width: 800px;
  }

  p {
    width: 760px !important;
    margin-left: 300px !important;
  }
</style>

<body>
  <h3 class="big-tit">菜谱列表</h3>
  <ul class="list-box">
    <!-- <li>
      <a href="info.html">
        <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="" />
        <h3>菜单名称</h3>
      </a>
    </li>
    -->
  </ul>
  <p class="more" style="display: none;">数据正在加载中...</p>
  <p class="noinfo">没有数据了...</p>
</body>
<script src="./lib/axios.js"></script>

<script>
  // http://124.223.14.236:3001/api
  axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

  //渲染菜单列表
  async function getMenuList() {
    const { data } = await axios.get('/recipe', {
      params: {
        pageSize: 24,
        pageNum: 1,
      }
    })
    if (!data.success) alert(data.msg)
    const htmlStr = data.data.list.map(item => {
      const imgUrl = 'http://124.223.14.236:3001/public/' + item.img;
      return `
          <li>
            <a href="./info.html?id=${item.id}">
              <img src=${imgUrl} alt="" />
              <h3 title="${item.name}">${item.name}</h3>
            </a>
          </li>
        `;
    }).join('')

    document.querySelector('.list-box').innerHTML = htmlStr
  }
  getMenuList()

</script>

</html>